package Main;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.lang.String;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import commands.CommandParser;
import commands.DateCommand;
import commands.DiceCommand;
import commands.FuckYouCommand;
import commands.HelpCommand;
import commands.IgnoreCommand;
import commands.MemeCommand;
import commands.OauthCommand;
import commands.PMCommand;
import commands.PingCommand;
import commands.PongCommand;
import commands.RandomMusicCommand;
import commands.ShutdownCommand;
import commands.TestCommand;
import commands.ToltalCommandUsesCommand;
import commands.UpdateGameCommand;
import net.dv8tion.jda.JDA;
import net.dv8tion.jda.JDABuilder;
import net.dv8tion.jda.events.message.MessageReceivedEvent;
import net.dv8tion.jda.utils.AvatarUtil;
import net.dv8tion.jda.utils.AvatarUtil.Avatar;

public class Main {
	String lol = null;
	public static String line = null;
	private static int update = 1;
	public static int numberOfLines = 1;
	public static String Update;
	public static File file = new File("C:/Users/Zachary/workspace/Java_Discord_Bot/src/SM.jpg");
	public static BufferedImage img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
	public static HashMap<String, Command> commands = new HashMap<String, Command>();
	private static JDA jda;
	public static String name = "Muffin Bot";
	public static final CommandParser parser = new CommandParser();
	
	public static void main(String[] args) throws InterruptedException, IOException {
		
		try {
			jda = new JDABuilder().addListener(new BotListener()).setBotToken("MTg2MzIwNjgwMzExMTkzNjAw.Civ3kg.RW57PIuTKi4SkyAz4jANkmTol7E").buildBlocking();
			jda.setAutoReconnect(true);
		}catch(Exception e){
			e.printStackTrace();
		}try{
			jda.getAccountManager().setGame(ToltalCommandUsesCommand.countT +" messages sent");
			InputStream is = new FileInputStream("C:/Users/Zachary/workspace/Java_Discord_Bot/src/SM.jpg");
			Avatar av = AvatarUtil.getAvatar(file);
			jda.getAccountManager().setAvatar(av).update();
		commands.put("ping", new PingCommand());
		commands.put("meme", new MemeCommand());
		commands.put("fuckyou", new FuckYouCommand());
		commands.put("total", new ToltalCommandUsesCommand());
		commands.put("sherlock", new TestCommand());
		commands.put("shutdown", new ShutdownCommand());
		commands.put("roll", new DiceCommand());
		commands.put("oauth", new OauthCommand());
		commands.put("help", new HelpCommand());
		commands.put("pong", new PongCommand());
		commands.put("prune", new PMCommand());
		commands.put("gupdate", new UpdateGameCommand());
		commands.put("ignore", new IgnoreCommand());
		commands.put("avatars", new DateCommand());
		commands.put("randmusic", new RandomMusicCommand());
		while(1==1){
		while(1==1 && update == 1){
			jda.getAccountManager().setGame(ToltalCommandUsesCommand.countT +" messages sent");
		Thread.sleep(5000);
		update = 2;
		}
		while(1==1 && update == 2){
			jda.getAccountManager().setGame("https://discordapp.com/oauth2/authorize?&client_id=186320666927169536&scope=bot");
		Thread.sleep(5000);
		update = 3;
		}
		while(1==1 && update == 3){
			jda.getAccountManager().setGame("Rick Rolls : " + DiceCommand.rcount);
		Thread.sleep(5000);
		update = 1;
		}	
			Thread.sleep(5000);	
		}
		}catch(Exception e){
			}
		}

	
	public static void handleCommand(CommandParser.CommandContainer cmd){
		if(commands.containsKey(cmd.invoke)){
			boolean safe = commands.get(cmd.invoke).called(cmd.args,cmd.event);
			
			if(safe){
				commands.get(cmd.invoke).action(cmd.args,cmd.event);
				commands.get(cmd.invoke).execute(safe,cmd.event);
			}else{
				
			}
		}
	}
}

